<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计划查询</title>
<link rel="stylesheet" type="text/css" href="../ext/resources/css/ext-all.css"></link>
<link rel="stylesheet" type="text/css" href="../ext/resources/css/xtheme-slate.css"></link>
<script src="../ext/adapter/ext/ext-base.js"></script>
<script src="../ext/ext-all.js"></script>
<script src="../ext/src/locale/ext-lang-zh_CN.js"></script>	
<script src="../ext/base/PagingMemoryProxy.js"></script>	
<script type="text/javascript">
Ext.onReady(function(){
	Ext.Ajax.on('requestcomplete',checkUserSessionStatus, this);      
	function checkUserSessionStatus(conn,response,options){      
	    if(response.getResponseHeader('sessionstatus')){      
	    	parent.location.href='/xdj/index.jsp';   
	    }      
	}  
	Ext.BLANK_IMAGE_URL='ext/resources/images/default/s.gif';
	
	
	//var sm = new Ext.grid.CheckboxSelectionModel();//列的复选框
	var cm=new Ext.grid.ColumnModel([
		new Ext.grid.RowNumberer(),  //自动增加序列号
		//sm, //加到每列的前边
		{header:'路线名称',dataIndex:'LineName',sortable:true},
		{header:'区域名称',dataIndex:'ZoneName'},
		{header:'设备名称',dataIndex:'DevName'}, //True表示为可在该列上进行排列
		{header:'巡检项目',dataIndex:'CHKItem'},
		{header:'项目类型',dataIndex:'CHKTypeName'},
		{header:'检查部位',dataIndex:'CHKPlace'},
		{header:'判断标准',dataIndex:'Standard'},
		{header:'值次名称',dataIndex:'DutyName'},
		{header:'值班名称',dataIndex:'ClaName'},
		{header:'轮次序号',dataIndex:'TurnOrder'},
		{header:'巡检人员',dataIndex:"UserName"},
		{header:'起始时间',dataIndex:'Start_PDA_CHKDateTime',width:200},
		{header:'终止时间',dataIndex:'End_PDA_CHKDateTime',width:200}
	]);//定义相应的列模型
	var store=new Ext.data.JsonStore({
	 	url: 'plan_queryPlan',
	 	//autoLoad : false,
	 	 root: 'result',
	 	// idProperty:'id',
		totalProperty:'totalProperty',
	    fields: ["LineName",
	             "ZoneName",
	             "DevName",
	             "CHKItem",
	             "CHKTypeName",
	             "CHKPlace",
	             "Standard",
	             "DutyName",
	             "ClaName",
	             "TurnOrder",
	             "UserName",
	             "Start_PDA_CHKDateTime",
	             "End_PDA_CHKDateTime"]
	});//存储前两项的定义的东西，将其连接起来
	                         	
	var panel = new Ext.grid.GridPanel({
	    cm:cm,
	    //sm:sm,
	    store:store,
	    autoHeight:true,  //设置表格的高度 true为自动获取表格的大小
	    renderTo:'grid' , //渲染容器
	    enableColumnMove:false,//不可以使表格列移动
	    enableColumnResize:false, //不可以改变列的宽度
	    stripeRows:false, //True表示为显示行的分隔符
	    loadMask:true,  //会有一个Ext.LoadMask的遮罩效果
	    trackMouseOver : true,  //True表示为鼠标移动时高亮显示（默认为true）。
	    enableDragDrop : true,
	    viewConfig:{
	      forceFit:true //让没列自动填满表格，根据你设置的宽度按比例分配
	    },
	    bbar:new Ext.PagingToolbar({
	    	pageSize : 10, //每页显示几条
			store : store,
			beforePageText:"当前第",   
            afterPageText:"页，共{0}页",   
            lastText:"尾页",   
            nextText :"下一页",   
            prevText :"上一页",   
            firstText :"首页",                           
	        displayInfo:true, 
	        displayMsg:'显示第{0}条数据到{1}条数据,一共有{2}条', 
	        emptyMsg:'没有记录'
	  })
	 });
	store.load({params:{start:0,limit:10}});//加载数据  注意，一旦使用了分页条， store.load();就必须在构造表格之后进行执行，否则将不起作用，并且将分页条和数据源关联，从而实现与表格共享数据模型

	//右面表单信息
	var lineStore=new Ext.data.JsonStore({
	 	url: 'chkline_load',
	 	autoLoad : true,
	    fields: ["lineName", "isCHKOrder","lineDesc","professName","lineID","professID"]
	});
	var dutyStore=new Ext.data.JsonStore({
		url:'../base/duty_load',
		autoLoad : true,
		fields:['dutyID','name','remark']
	});
	var classStore=new Ext.data.JsonStore({
		url: '../base/class_load',
		autoLoad : true,
	  	fields: [{name:'id'}, {name:'name'},{name:'startTime',type:Ext.data.Types.DATE,dateFormat:'Y-m-d H:i:s'},{name:'endTime',type:Ext.data.Types.DATE,dateFormat:'Y-m-d H:i:s'}]
	});
	var form=new Ext.form.FormPanel({
		frame:true,
		//height:100,
		labelAlign:'right',
		//labelWidth:55,
		buttonAlign:'left',
		//columnWidth:.60,
		layout:'column',
		items:[
			{
				layout:'form',
				labelWidth:60,
				items:[{
					fieldLabel:'值班日期',
					id:'chkdate',
					width:150,
					xtype:'datefield'
				}]	
			},{ layout:'form',
				labelWidth:60,
				items:[{
					xtype:'combo',
					fieldLabel: '巡检路线',
	                hiddenName:'lineID',
	                emptyText:'--请选择--',
	                forceSelection: true,
	               // listWidth: 150,
	                store: lineStore,
	                valueField:'lineID',
	                displayField:'lineName',
	                typeAhead: true,
	                mode: 'local',
	                triggerAction: 'all',
	                selectOnFocus:true,
	                allowBlank:true
				}],
			},{ layout:'form',
				labelWidth:60,
				items:[{
					xtype:'combo',
					fieldLabel: '巡检值次',
	                hiddenName:'dutyID',
	                emptyText:'--请选择--',
	                forceSelection: true,
	                listWidth: 150,
	                store: dutyStore,
	                valueField:'dutyID',
	                displayField:'name',
	                typeAhead: true,
	                mode: 'local',
	                triggerAction: 'all',
	                selectOnFocus:true,
	                allowBlank:true
				}],
			},{ layout:'form',
				labelWidth:60,
				items:[{
					xtype:'combo',
					fieldLabel: '巡检班次',
	                hiddenName:'classID',
	                emptyText:'--请选择--',
	                forceSelection: true,
	                listWidth: 150,
	                store: classStore,
	                valueField:'id',
	                displayField:'name',
	                typeAhead: true,
	                mode: 'local',
	                triggerAction: 'all',
	                selectOnFocus:true,
	                allowBlank:true
				}]
			}],
		buttons:[{
	    	text: "查询",disabled:true,id:'cFindBox',
	        handler:function(){
	        	if ( form.getForm().isValid() ){
	        		var chkdate = Ext.getCmp("chkdate").getValue();
	        		if(chkdate==null||chkdate=='') {
	        			chkdate = new Date();
	        			chkdate.setHours(0, 0, 0, 0);
	        		}//alert(chkdate.format('Y-m-d'));
	        		store.load({
	        			params:{
	        				dutyDate:chkdate.format('Y-m-d'),
	        				chkLineID:form.getForm().findField("lineID").getValue()==''?-1:form.getForm().findField("lineID").getValue(),
	    	        		dutyID:form.getForm().findField("dutyID").getValue()==''?-1:form.getForm().findField("dutyID").getValue(),
	    	        		classID:form.getForm().findField("classID").getValue()==''?-1:form.getForm().findField("classID").getValue()
	    	        	}
	        		});
	        	}
	       }
	    },{
	    	text: "导出 ",disabled:true,id:'cSaveToExcel',
	        handler:function(){
	        	if ( form.getForm().isValid() ){
	        		var chkdate = Ext.getCmp("chkdate").getValue();
	        		if(chkdate==null||chkdate=='') {
	        			chkdate = new Date();
	        			chkdate.setHours(0, 0, 0, 0);
	        		}
    				var dutyDate = chkdate.format('Y-m-d');
    				var chkLineID = form.getForm().findField("lineID").getValue()==''?-1:form.getForm().findField("lineID").getValue();
    				var dutyID = form.getForm().findField("dutyID").getValue()==''?-1:form.getForm().findField("dutyID").getValue();
    				var classID = form.getForm().findField("classID").getValue()==''?-1:form.getForm().findField("classID").getValue();
    				window.location.href = "plan_export?dutyDate="+dutyDate+"&chkLineID="+chkLineID+"&dutyID="+dutyID+"&classID="+classID;
	        		
	        	}
	       }
	    },{	
	        	hidden:true,
				width:70	
		}]
	});
	Ext.getCmp("chkdate").setValue(new Date());
	 new Ext.Viewport({  
		layout : 'border', // 使用border布局  
		border:false,
		items:[{
			
			region:'center',
			border:false,
			items:[form,panel]
		}],
		listeners:{
			'beforerender' : function(cmp) {
				// set role
				var store=new Ext.data.JsonStore({
					url: '../system/role_loadFunc?funcCode=ControlPlanFind',
					autoLoad : true,
					fields: ["functioncode"]
				});
				store.load({
				    callback: function(records, options, success){
				    	var i=0;
				    	for(; i<records.length; i++) {
				    		var id = records[i].get("functioncode");
				    		//alert('d'+Ext.getCmp('56').text);
				    		if(Ext.getCmp(id)!=null) {
				    			Ext.getCmp(id).setDisabled(false);
				    		}
				        }
				    },
				    scope: store
				});
			}
		}
	 }); 
	 
});
</script> 	
</head>
<body>
<div id="grid"></div>
</body>
</html>